<?php

namespace app\common\service\webscoket;

use app\job\OrderAssignJob;
use app\job\SwooleTaskJob;
use app\webscoket\Manager;
use think\facade\Log;
use think\facade\Queue;
use think\swoole\Websocket;
class SwooleTaskService
{
    public static function ceshi()
    {
        $fds = CacheService::sMembers('_ws_user4');
        $fd = $fds[0];
        $server = app()->make(Websocket::class);
//        $server = app('swoole.server');
        if ($server->isEstablished($fd)) {
            // 推送消息到 WebSocket 客户端
            $server->to($fd)->push(json_encode(['msg'=>'我看看']));
            Log::write("在");
        }else{
            Log::write("不在");
        }
//        Queue::push(SwooleTaskJob::class, [
//            'type'=>'message',
//            'data'=>[]
//        ]);
//        $manager = app()->make(Manager::class);
//        var_dump($manager);exit();
echo "发送";exit();
//        $fd = CacheService::sMembers('_ws_user4'); // 获取FD
//        if($fd){
//            $server = app()->make(Websocket::class);
//            $server->to($fd[0])->push(json_encode(['msg' => 'nihao']));
//            var_dump($server->getSender());exit();
//        }
    }
}